package com.common.facebody.instance;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.common.facebody.config.FaceBodyConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author 牧鱼
 * @date 2021-4-25
 */
@Component
public class FaceBodyInstance {

    private static final Logger log = LoggerFactory.getLogger(FaceBodyInstance.class);

    private Float faceBodyScore ;
    /**
     * 人脸识别对接阿里实例对象
     */
    private IAcsClient client;

    /**
     * 实例化人脸
     * @param faceBodyConfig
     */
    public FaceBodyInstance(FaceBodyConfig faceBodyConfig) {
        log.info("初始化人脸识别开始");
        long startTime = System.currentTimeMillis();
        DefaultProfile profile = DefaultProfile.getProfile(
                faceBodyConfig.getRegionId(),
                faceBodyConfig.getAccessKeyId(),
                faceBodyConfig.getAccessKeySecret()
        );
        log.info("初始化人脸识别成功");
        client = new DefaultAcsClient(profile);
        faceBodyScore = faceBodyConfig.getFaceBodyScore();
        log.info("初始化人脸识别结束：耗时：{"+ (System.currentTimeMillis()-startTime) +"}MS");
    }

    public Float getFaceBodyScore() {
        return faceBodyScore;
    }

    public IAcsClient getClient() {
        return client;
    }
}
